{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "滑动窗口解法：\n",
    "- cache：记录不重复的值，如果遇到重复值，则更新到新的坐标。\n",
    "- start: 左指针，开始的位置，当遇到重复值时，就把start的值设置为原记录的值的下一个下标cache[c]+1。\n",
    "- idx：下标相当于右指针，不断的遍历，下标值+1\n",
    "- cur:当前筛选长度idx - start +1\n",
    "- res:记录最大长度"
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "source": [
    "class Solution:\n",
    "    def lengthOfLongestSubstring(self, s: str) -> int:\n",
    "        start, res, cache = 0, 0, {}\n",
    "        for idx, c in enumerate(s):\n",
    "            if c in cache and cache[c] >= start:\n",
    "                start = cache[c]+1\n",
    "                cache[c] = idx\n",
    "            else:\n",
    "                cache[c] = idx\n",
    "                cur = idx - start +1\n",
    "                res = max(res, cur)\n",
    "                \n",
    "        return res\n",
    "    \n",
    "#-------------\n",
    "if __name__ == '__main__':\n",
    "    s = 'df23qw32e434222223vf2ne2rq'\n",
    "    a = Solution()\n",
    "    b = a.lengthOfLongestSubstring(s)\n",
    "    print(b)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "6\n"
     ]
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.9.0",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.9.0 64-bit ('universe': virtualenv)"
  },
  "interpreter": {
   "hash": "efc9d12c894566d142e82a9dae601d559d62f10cdf97a3f3ead6efac69d368e5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}